
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>

<%
    try {
        // 数据库连接信息（请根据实际情况修改）
        String url = "jdbc:mysql://localhost:3306/educate";
        String dbUser = "root";
        String dbPassword = "123456";

        // 加载数据库驱动
        Class.forName("com.mysql.jdbc.Driver");

        // 建立数据库连接
        Connection conn = DriverManager.getConnection(url, dbUser, dbPassword);

        // 查询最新的反馈
        String sql = "SELECT name, rating, category, message, submit_time FROM feedback ORDER BY submit_time DESC LIMIT 10";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        ResultSet rs = pstmt.executeQuery();

        // 显示反馈内容
        while (rs.next()) {
            String name = rs.getString("name");
            int rating = rs.getInt("rating");
            String category = rs.getString("category");
            String message = rs.getString("message");
            Date submitTime = rs.getTimestamp("submit_time");

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String formattedTime = sdf.format(submitTime);

%>
            <div class="feedback-item">
                <h3><%= name %></h3>
                <p><%= message %></p>
                <p><strong>评分:</strong> <%= rating %> <strong>分类:</strong> <%= category %> <strong>提交时间:</strong> <%= formattedTime %></p>
            </div>
<%
        }

        // 关闭数据库连接
        rs.close();
        pstmt.close();
        conn.close();
    } catch (Exception e) {
        e.printStackTrace();
%>
        <div class="feedback-item">
            <p>无法加载反馈内容，请稍后再试。</p>
        </div>
<%
    }
%>
